import 'package:flutter/material.dart';
import 'package:flutter_app/app/forms/dy_admin_login_form.dart';
import 'package:nylo_framework/nylo_framework.dart';

class LoginForm extends StatefulWidget {
  const LoginForm({super.key});

  static String state = "login_form";

  @override
  createState() => _LoginFormState();
}

class _LoginFormState extends NyState<LoginForm> {
  final TextEditingController _usernameController = TextEditingController();
  final TextEditingController _passwordController = TextEditingController();

  _LoginFormState() {
    stateName = LoginForm.state;
  }

  @override
  init() async {}

  @override
  stateUpdated(dynamic data) async {
    // e.g. to update this state from another class
    // updateState(LoginForm.state, data: "example payload");
  }

  @override
  Widget build(BuildContext context) {
    DyAdminLoginForm form = DyAdminLoginForm(name: "dy_admin_login_form");
    return Column(
      children: [
        NyForm(form: form),
        SizedBox(height: 20),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () {
                // e.g. to update this state from another class
                // updateState(LoginForm.state, data: "example payload");
                form.submit(onSuccess: (data)=>{
                  print(data)
                });
              },
              child: Text("Login".tr()),
            ),
          ],
        ),
      ],
    );
  }
}
